package com.roger.tool.utils;

import android.content.Context;
import android.os.Looper;
import android.widget.Toast;

public class ToastUtil {

	/**
	 * @param pContext
	 * @param text
	 * @param duration
	 */
	public static void show(final Context pContext, final String text, final int duration) {

		if (!(Thread.currentThread() == Looper.getMainLooper().getThread())) {
			new Thread(new Runnable() {

				@Override
				public void run() {
					Looper.prepare();
					Toast.makeText(pContext, text, duration).show();
					Looper.loop();
				}
			}).start();
		} else {
			Toast.makeText(pContext, text, duration).show();
		}

	}

	public static void showLong(final Context pContext, final String text) {

		ToastUtil.show(pContext, text, Toast.LENGTH_LONG);

	}

	public static void showShort(final Context pContext, final String text) {

		ToastUtil.show(pContext, text, Toast.LENGTH_SHORT);

	}

}
